<html>
<head><meta charset="utf-8"><title>drop vs construction from const · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html">drop vs construction from const</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216729919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216729919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216729919">(Nov 14 2020 at 13:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Questions.20regarding.20Heap.20allocation.20in.20const.20eval/near/216635183">said</a>:</p>
<blockquote>
<p>the same with <code>const FOO: String = String::new();</code></p>
</blockquote>
<p>so, this is actually really really tricky, isn't it? In particular, this means there is a proof obligation in <code>const fn String__new</code>  that <em>the value returned here will cause <code>drop</code> to be a NOP</em>. Because <code>drop</code> <em>will</em> be called in such a const when it gets used.<br>
Or is the argument that, since no allocation could possibly have been made as part of this (as CTFE wouldnt allow that), ergo <code>drop</code> cannot soundly deallocate any allocation anyway? Hm... I have a hard time turning this into something that I could formalize in Coq, which worries me.^^</p>



<a name="216730063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730063">(Nov 14 2020 at 13:47)</a>:</h4>
<p>I think the theorem we'd need here is "if CTFE completes without an error, then the value it produced is also a value that executing the same code at runtime could have produced". Then we can show that there cannot be an allocation after running this code, so any call to <code>free</code> by <code>drop</code> would be a soundness issue.</p>



<a name="216730099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730099">(Nov 14 2020 at 13:48)</a>:</h4>
<p>This works fine, until we give users the ability to execute different code at runtime vs compiletime^^</p>



<a name="216730588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730588">(Nov 14 2020 at 13:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Questions.20regarding.20Heap.20allocation.20in.20const.20eval/near/216729919">said</a>:</p>
<blockquote>
<p>so, this is actually really really tricky, isn't it? In particular, this means there is a proof obligation in <code>const fn String__new</code>  that <em>the value returned here will cause <code>drop</code> to be a NOP</em>. Because <code>drop</code> <em>will</em> be called in such a const when it gets used.<br>
Or is the argument that, since no allocation could possibly have been made as part of this (as CTFE wouldnt allow that), ergo <code>drop</code> cannot soundly deallocate any allocation anyway? Hm... I have a hard time turning this into something that I could formalize in Coq, which worries me.^^</p>
</blockquote>
<p>That's not how I see it. I see no relation to dropping or any further processing here. That is an effect (no effect system pun intended) of the fact that <code>const</code> items are actually just constructors of their type</p>



<a name="216730642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730642">(Nov 14 2020 at 13:58)</a>:</h4>
<p>I always like the example of the "zst-no-fields-struct-but-!Copy" situation: <code>struct Foo; const FOO: Foo = Foo;</code>. You can use <code>Foo</code> everywhere to construct values of type <code>Foo</code>, and you can use <code>FOO</code> everywhere to construct values of type <code>Foo</code>. There's no copy happening. It's construction that is happening</p>



<a name="216730647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730647">(Nov 14 2020 at 13:58)</a>:</h4>
<p>in the case of constants, that construction can be arbitrarily complex</p>



<a name="216730658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730658">(Nov 14 2020 at 13:59)</a>:</h4>
<p>let's split the discussion here, zulip has threads after all</p>



<a name="216730722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730722">(Nov 14 2020 at 14:01)</a>:</h4>
<p>but what are the subthreads?^^</p>



<a name="216730735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730735">(Nov 14 2020 at 14:01)</a>:</h4>
<p>one moment</p>



<a name="216730786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730786">(Nov 14 2020 at 14:02)</a>:</h4>
<p>I kept the stuff about the different allocators in the original thread</p>



<a name="216730792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730792">(Nov 14 2020 at 14:02)</a>:</h4>
<p>this thread is now just about our mental models of constants and their uses</p>



<a name="216730858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730858">(Nov 14 2020 at 14:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Questions.20regarding.20Heap.20allocation.20in.20const.20eval/near/216730642">said</a>:</p>
<blockquote>
<p>I always like the example of the "zst-no-fields-struct-but-!Copy" situation: <code>struct Foo; const FOO: Foo = Foo;</code>. You can use <code>Foo</code> everywhere to construct values of type <code>Foo</code>, and you can use <code>FOO</code> everywhere to construct values of type <code>Foo</code>. There's no copy happening. It's construction that is happening</p>
</blockquote>
<p>that's not what I mean though -- String::new could be doing arbitrary things but we have to somehow argue why calling <code>drop</code> on the value it returned will not be UB <em>even though</em> we are executing things "in a weird way" (partially at compile-time, with a memoized result).</p>



<a name="216730891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730891">(Nov 14 2020 at 14:05)</a>:</h4>
<p>if you dig down into why that is correct, I think you end up with the same result: soundness is given only if the CTFE execution already is a possible runtime execution, and thus covered by the existing soundness proof for this unsafe code</p>



<a name="216730938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730938">(Nov 14 2020 at 14:06)</a>:</h4>
<p>I get that <code>String::new</code> is arbitrarily complex, but it produces a single value, which, if created manually via just constructors (ignoring privacy), could totally be repeated arbitrarily often without causing problems.</p>



<a name="216730958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730958">(Nov 14 2020 at 14:07)</a>:</h4>
<p>FWIW, a curious hack I just through of for your proposed primitive for dispatching to different code at const-time vs runtime is that we could say that, <em>for the purpose of a soundness proof</em>, you have to show that either choice works. IOW, in the Abstract Machine, we non-determinisitcally pick one or the other branch. But then we make an extra guarantee that the runtime implementation will always pick one branch and the CTFE implementation will always pick the other.</p>



<a name="216730960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216730960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216730960">(Nov 14 2020 at 14:07)</a>:</h4>
<p>well... <code>"foo".to_string()</code> would be a possible runtime execution, and we could trivially allow it in CTFE by sprinkling <code>const</code> around and implementing some allocator functions.</p>



<a name="216731016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731016">(Nov 14 2020 at 14:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/drop.20vs.20construction.20from.20const/near/216730960">said</a>:</p>
<blockquote>
<p>well... <code>"foo".to_string()</code> would be a possible runtime execution, and we could trivially allow it in CTFE by sprinkling <code>const</code> around and implementing some allocator functions.</p>
</blockquote>
<p>but our proof wouldnt work any more. note how my proof relied on executing the code in an Absract Machine <em>with no allocator</em> to show that "switching" from the compile-time to the run-time allocator cannot cause trouble. that's part of the "weird way".</p>



<a name="216731017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731017">(Nov 14 2020 at 14:08)</a>:</h4>
<p>oh... I like that (wrt the ctfe/runtime switching logic). I mean, runtime is in fact allowed to arbitrarily switch to the compile-time version. It may even make sense to do so in debug mode</p>



<a name="216731027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731027">(Nov 14 2020 at 14:09)</a>:</h4>
<p>uh</p>



<a name="216731031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731031">(Nov 14 2020 at 14:09)</a>:</h4>
<p>ok, I'm confused now about the allocator switching</p>



<a name="216731032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731032">(Nov 14 2020 at 14:09)</a>:</h4>
<p>why is there allocator switching?</p>



<a name="216731037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731037">(Nov 14 2020 at 14:10)</a>:</h4>
<p>the allocations done at compiletime dont go through <code>malloc</code></p>



<a name="216731082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731082">(Nov 14 2020 at 14:10)</a>:</h4>
<p>so when you use a compile-time generated value at runtime, you are switching out the allocator "beneath its feet"</p>



<a name="216731083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731083">(Nov 14 2020 at 14:10)</a>:</h4>
<p>yes, and for <code>String::new()</code> they actually never will</p>



<a name="216731096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731096">(Nov 14 2020 at 14:10)</a>:</h4>
<p>oh... you're talking about the transient heap allocs?</p>



<a name="216731114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731114">(Nov 14 2020 at 14:11)</a>:</h4>
<p>right but that's why "implementing some allocator functions" to support <code>"foo".to_string()</code> would be wrong</p>



<a name="216731117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731117">(Nov 14 2020 at 14:11)</a>:</h4>
<p>like if we just reused <code>Global</code> during CTFE to mean "transient"?</p>



<a name="216731121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731121">(Nov 14 2020 at 14:11)</a>:</h4>
<p>(we know it is wrong as <code>drop</code> would cause UB, but we have to explain where the proof fails)</p>



<a name="216731130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731130">(Nov 14 2020 at 14:11)</a>:</h4>
<p>I was not talking about transient allocations</p>



<a name="216731135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731135">(Nov 14 2020 at 14:11)</a>:</h4>
<p>I thought you meant</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">FOO</span>: <span class="nb">String</span> <span class="o">=</span><span class="w"> </span><span class="s">"foo"</span><span class="p">.</span><span class="n">to_string</span><span class="p">();</span><span class="w"></span>
</code></pre></div>



<a name="216731190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731190">(Nov 14 2020 at 14:12)</a>:</h4>
<p>transient allocations do not have to be "switched" since they are transient. so yes that explains why <code>Global</code> can be used for transient allocations.</p>



<a name="216731206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731206">(Nov 14 2020 at 14:13)</a>:</h4>
<p>the more I think about this the more I feel like treating CTFE allocation (at least those we want to carry over to be accessible at runtime) as a separate allocator makes a huge lot of sense :D</p>



<a name="216731325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731325">(Nov 14 2020 at 14:16)</a>:</h4>
<p>ok, let's expand some types here: <code>const FOO: String&lt;Global&gt; = String::&lt;Global&gt;::new();</code> is what happens "today" (assuming <code>impl&lt;A&gt; String&lt;A&gt; { fn new() -&gt; Self { ... }}</code>, and <code>struct String&lt;A = Global&gt;(...);</code>), because using <code>const FOO: String</code> will pick <code>Global</code> from the default and thus use <code>Global</code> for <code>String::new()</code></p>



<a name="216731396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216731396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216731396">(Nov 14 2020 at 14:18)</a>:</h4>
<p>But under the system we're talking about we'd need <code>const FOO: String&lt;Const&gt; = String::&lt;Const&gt;::new();</code>, which would break existing code. Though, because <code>new</code> has no <code>AllocRef</code> bound, we can probably figure out that <code>const FOO: String&lt;Global&gt; = String::&lt;Global&gt;::new();</code> is fine, because the <code>Global</code> is guaranteed to not be used in the body of <code>new</code></p>



<a name="216732013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732013">(Nov 14 2020 at 14:34)</a>:</h4>
<p>I think we're talking about different things</p>



<a name="216732067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732067">(Nov 14 2020 at 14:34)</a>:</h4>
<p>this thread started out with the current sitaution, i.e. no <code>Const</code> allocator. the question is: why is what we currently do sound, what are the key proof obligations?</p>



<a name="216732102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732102">(Nov 14 2020 at 14:35)</a>:</h4>
<p>I didnt mean to add a CTFE allocator in this thread</p>



<a name="216732167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732167">(Nov 14 2020 at 14:36)</a>:</h4>
<p>the proof obligation is that any code we use cannot have any allocator usage at all. Firstly, because we don't have <code>impl const</code> and secondly because we don't have any generic bounds beyond <code>Sized</code></p>



<a name="216732190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732190">(Nov 14 2020 at 14:36)</a>:</h4>
<p>thus there are no allocations by definition, so there can't be any deallocations</p>



<a name="216732208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732208">(Nov 14 2020 at 14:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/drop.20vs.20construction.20from.20const/near/216732167">said</a>:</p>
<blockquote>
<p>the proof obligation is that any code we use cannot have any allocator usage at all. Firstly, because we don't have <code>impl const</code> and secondly because we don't have any generic bounds beyond <code>Sized</code></p>
</blockquote>
<p>I agree we cannot have allocator usage but the reason is simply that CTFE hasnt implemented them. no need to talk about trait bounds IMO.</p>



<a name="216732217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732217">(Nov 14 2020 at 14:37)</a>:</h4>
<p>true</p>



<a name="216732221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732221">(Nov 14 2020 at 14:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/drop.20vs.20construction.20from.20const/near/216732190">said</a>:</p>
<blockquote>
<p>thus there are no allocations by definition, so there can't be any deallocations</p>
</blockquote>
<p>that is much more tricky though because you switched to a different execution engine mid-way! suddenly we are in unrestricted runtime code.</p>



<a name="216732274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732274">(Nov 14 2020 at 14:38)</a>:</h4>
<p>hmm</p>



<a name="216732282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732282">(Nov 14 2020 at 14:38)</a>:</h4>
<p>ok, yea, I don't have a good mental image of how this switch affects any proofs (not that I have a great understanding of proofs at all)</p>



<a name="216732306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732306">(Nov 14 2020 at 14:39)</a>:</h4>
<p>but going back to my suggestion about the value of a constant being in fact a constructor, why can't that be the boundary</p>



<a name="216732315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732315">(Nov 14 2020 at 14:39)</a>:</h4>
<p>no context swithcing necessary</p>



<a name="216732321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732321">(Nov 14 2020 at 14:39)</a>:</h4>
<p>CTFE is just procedural generation of constructor "expressions"</p>



<a name="216732515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732515">(Nov 14 2020 at 14:42)</a>:</h4>
<p>I dont know what a "constructor" is, in a way that would be useful for a proof</p>



<a name="216732541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732541">(Nov 14 2020 at 14:43)</a>:</h4>
<p>for <code>struct Foo(i32, u32)</code> a constructor is the <code>Foo</code> function with the signature <code>fn(i32, u32) -&gt; Foo</code></p>



<a name="216732552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732552">(Nov 14 2020 at 14:43)</a>:</h4>
<p>for tuples it's the <code>(a, b, c)</code> expression</p>



<a name="216732601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732601">(Nov 14 2020 at 14:44)</a>:</h4>
<p>yeah but that's all syntactic</p>



<a name="216732610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732610">(Nov 14 2020 at 14:44)</a>:</h4>
<p>which is useless, we need a semantic statement. something about the <em>behavior</em> of this code.</p>



<a name="216732619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732619">(Nov 14 2020 at 14:44)</a>:</h4>
<p>clearly, syntactically, <code>const</code> are in general <em>not</em> constructors</p>



<a name="216732645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732645">(Nov 14 2020 at 14:45)</a>:</h4>
<p>their use via the name behave very similarly to constructors</p>



<a name="216732659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732659">(Nov 14 2020 at 14:45)</a>:</h4>
<p>so <code>let x = FOO;</code> is very similar to <code>let x = Foo;</code></p>



<a name="216732681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732681">(Nov 14 2020 at 14:45)</a>:</h4>
<p>if we assume that every CTFE execution is a valid runtime execution, then we can argue that the specification for any use of a <code>const FOO</code> is to just copy-paste the <code>FOO</code> body to all usage sites. the fact that we pre-compute the const and only put in the result is not observable (*).</p>



<a name="216732683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732683">(Nov 14 2020 at 14:45)</a>:</h4>
<p>a different view, maybe this works better than the constructor analogy, is that a use of a constant is actually a runtime <code>transmute</code> call from some arbitrary bits</p>



<a name="216732744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732744">(Nov 14 2020 at 14:46)</a>:</h4>
<p>hmm</p>



<a name="216732759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732759">(Nov 14 2020 at 14:46)</a>:</h4>
<p>but does that view about copy pasting the body really help? that would work for <code>"foo".to_string()</code></p>



<a name="216732760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732760">(Nov 14 2020 at 14:46)</a>:</h4>
<p>and <em>additionally</em> we know that this pre-computation does not involve any calls to the allocator</p>



<a name="216732763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732763">(Nov 14 2020 at 14:46)</a>:</h4>
<p>oh</p>



<a name="216732797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732797">(Nov 14 2020 at 14:47)</a>:</h4>
<p>so putting these two together, this means that the <code>const</code> body could have been run at runtime without any call to an allocator. so there <em>might</em> at runtime be no actual allocation. which means <code>drop</code> (and any other function) needs to already be correct for the case where there is no allocation.</p>



<a name="216732813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732813">(Nov 14 2020 at 14:47)</a>:</h4>
<p>oh</p>



<a name="216732817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732817">(Nov 14 2020 at 14:47)</a>:</h4>
<p>yea</p>



<a name="216732876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216732876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216732876">(Nov 14 2020 at 14:48)</a>:</h4>
<p>ok, I was about to ask about transient allocs, but the way you wrote it now it makes it clear that these are irrelevant, because you could have written the code without transient allocs and emitted the same result</p>



<a name="216733110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733110">(Nov 14 2020 at 14:52)</a>:</h4>
<p>right now, the fact that CTFE succeeds proves that there <em>are</em> no transient allocs.</p>



<a name="216733136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733136">(Nov 14 2020 at 14:53)</a>:</h4>
<p>argml, right, sorry I keep forgetting we're talking about proving the current status</p>



<a name="216733146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733146">(Nov 14 2020 at 14:53)</a>:</h4>
<p>once we allow transient allocs, the argument becomes more tricky. we can still block heap allocs at the interner, so we know that the final value cannot point to any heap allocation, but <em>in theory</em> one could imagine allocators <em>for which this is not enough</em></p>



<a name="216733212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733212">(Nov 14 2020 at 14:54)</a>:</h4>
<p>well, won't that be the allocator's fault if they made their trait impls <code>const</code>?</p>



<a name="216733222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733222">(Nov 14 2020 at 14:54)</a>:</h4>
<p>like, imagine every call to <code>alloc</code> is globally registered somewhere, and there is a way to inspect those allocations even if all other pointers to them got lost. now if CTFE performs allocations and does not "carry them over", they will be observably missing from that global registry.</p>



<a name="216733248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733248">(Nov 14 2020 at 14:54)</a>:</h4>
<p>I mean if we start hooking <code>Global::alloc</code> in CTFE, we dont even know what <code>#[global_allocator]</code> will be...</p>



<a name="216733272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733272">(Nov 14 2020 at 14:55)</a>:</h4>
<p>you can't access static items in <code>const fn</code>, so you can't have a global registry of allocations</p>



<a name="216733273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733273">(Nov 14 2020 at 14:55)</a>:</h4>
<p>so we cant really blame the allocator. unless we explicitly make this part of the contract. somehow.</p>



<a name="216733292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733292">(Nov 14 2020 at 14:55)</a>:</h4>
<p>oh</p>



<a name="216733300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733300">(Nov 14 2020 at 14:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/drop.20vs.20construction.20from.20const/near/216733272">said</a>:</p>
<blockquote>
<p>you can't access static items in <code>const fn</code>, so you can't have a global registry of allocations</p>
</blockquote>
<p>I was talking about what the runtime allocator would do. of course our CTFE hooks would do nothing like that.</p>



<a name="216733312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733312">(Nov 14 2020 at 14:56)</a>:</h4>
<p>hehe, ok, that is indeed weird</p>



<a name="216733352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733352">(Nov 14 2020 at 14:56)</a>:</h4>
<p>but when we permit <code>Global::alloc</code> to be called during CTFE, <em>we have no clue</em> what runtime code we are supposed to "emulate" here</p>



<a name="216733386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733386">(Nov 14 2020 at 14:57)</a>:</h4>
<p>I think we can safely ignore that</p>



<a name="216733432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733432">(Nov 14 2020 at 14:58)</a>:</h4>
<p>you can't possibly build a communication channel between that allocator at compile-time and at runtime</p>



<a name="216733435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733435">(Nov 14 2020 at 14:58)</a>:</h4>
<p>there's no API for it</p>



<a name="216733436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733436">(Nov 14 2020 at 14:58)</a>:</h4>
<p>that is exactly the problem</p>



<a name="216733445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733445">(Nov 14 2020 at 14:58)</a>:</h4>
<p>because if allocation is a runtime-only thing, you <em>can</em> have a "communication channel" between all allocator functions</p>



<a name="216733446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733446">(Nov 14 2020 at 14:58)</a>:</h4>
<p>and between an unknown set of extra functions</p>



<a name="216733455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733455">(Nov 14 2020 at 14:59)</a>:</h4>
<p>sure, but none of this functionality is available at compile-time</p>



<a name="216733456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733456">(Nov 14 2020 at 14:59)</a>:</h4>
<p>I am fairly certain I can craft a (horrible) example where everything goes very wrong but none of the proof obligations we have spelled out so far is violated</p>



<a name="216733458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733458">(Nov 14 2020 at 14:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/drop.20vs.20construction.20from.20const/near/216733455">said</a>:</p>
<blockquote>
<p>sure, but none of this functionality is available at compile-time</p>
</blockquote>
<p>that doesnt matter</p>



<a name="216733461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733461">(Nov 14 2020 at 14:59)</a>:</h4>
<p>the point is, <em>you can observe whether heap allocations happened</em></p>



<a name="216733508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733508">(Nov 14 2020 at 15:00)</a>:</h4>
<p>and now CTFE lets you <em>run code where heap allocations definitely happened</em>, but in a way that cannot be observed</p>



<a name="216733515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733515">(Nov 14 2020 at 15:00)</a>:</h4>
<p>ergo we have unsoundness</p>



<a name="216733537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733537">(Nov 14 2020 at 15:01)</a>:</h4>
<p>so basically you make a <code>MyThing</code> struct marker type that just does <code>drop(Box::new(42))</code> internally and since we get a <code>MyThing</code> marker value, that we can put into the return value of the constant, runtime code can read that marker value and thus assume that this specific heap alloc has happend</p>



<a name="216733585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733585">(Nov 14 2020 at 15:02)</a>:</h4>
<p>very roughly speaking:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// Type invariant: constructing an element of this type will cause a heap allocation</span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Evil</span><span class="p">(());</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Evil</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">pub</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">drop</span><span class="p">(</span><span class="nb">Box</span>::<span class="n">new</span><span class="p">(</span><span class="mi">0</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="n">Evil</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>

<span class="w">  </span><span class="k">pub</span><span class="w"> </span><span class="n">check</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">number_of_heap_allocs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="cm">/* call private allocator API */</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">number_of_heap_allocs</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">unreachable_unchecked</span><span class="p">()</span><span class="w"> </span><span class="p">}}</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216733586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733586">(Nov 14 2020 at 15:02)</a>:</h4>
<p>this code is sound if you remove the <code>const</code></p>



<a name="216733590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733590">(Nov 14 2020 at 15:02)</a>:</h4>
<p>damn <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span></p>



<a name="216733592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733592">(Nov 14 2020 at 15:02)</a>:</h4>
<p>but unsond with <code>const</code></p>



<a name="216733595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733595">(Nov 14 2020 at 15:02)</a>:</h4>
<p>so clearly there is some extra proof obligation required <em>somewhere</em></p>



<a name="216733598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733598">(Nov 14 2020 at 15:02)</a>:</h4>
<p>well, only unsound if you do <code>fn check(&amp;self)</code></p>



<a name="216733604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733604">(Nov 14 2020 at 15:02)</a>:</h4>
<p>thats what soundness means</p>



<a name="216733606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733606">(Nov 14 2020 at 15:02)</a>:</h4>
<p>that you can do arbitrary safe things</p>



<a name="216733621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733621">(Nov 14 2020 at 15:03)</a>:</h4>
<p>oh you mean I had a typo^^ fixed</p>



<a name="216733623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733623">(Nov 14 2020 at 15:03)</a>:</h4>
<p>jup</p>



<a name="216733626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733626">(Nov 14 2020 at 15:03)</a>:</h4>
<p>I agree, this is a problem</p>



<a name="216733641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733641">(Nov 14 2020 at 15:04)</a>:</h4>
<p>now, compilers will <em>already</em> happily remove calls to <code>malloc</code> when the result is unused</p>



<a name="216733681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733681">(Nov 14 2020 at 15:04)</a>:</h4>
<p>so I think the best fix is to make this part of the contract for <code>unsafe impl Allocator</code></p>



<a name="216733805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216733805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216733805">(Nov 14 2020 at 15:08)</a>:</h4>
<p>okay so we should write this up somewhere^^</p>



<a name="216736010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/drop%20vs%20construction%20from%20const/near/216736010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/drop.20vs.20construction.20from.20const.html#216736010">(Nov 14 2020 at 15:58)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/79045">https://github.com/rust-lang/rust/pull/79045</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>